package com.example.test.启动线程.公平非公平;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Loc {

    public static void main(String[] args) {

        AB ab = new AB();

        new Thread(ab).start();
        new Thread(ab).start();
        new Thread(ab).start();
    }
}


class AB implements Runnable {

    Lock lock = new ReentrantLock();

    @Override
    public void run() {
        while (true) {
            lock.lock();
            try {
                try {
                    Thread.sleep(1000);
                    System.out.println(Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } finally {
                lock.unlock();
            }
        }
    }
}